/**
 * @Author wangfan
 * @Date 2016/9/30 14:08
 */

package cn.ac.big.bigd.api.controller;


import cn.ac.big.bigd.util.EmailUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

@RestController
public class HomeController {




    @RequestMapping(value = {"","/"}, method = RequestMethod.GET)
    public Object home() {

        return "welcome";

    }


    @RequestMapping(value = {"hello"}, method = RequestMethod.GET)
    public Object hello() {
        try {


        StringBuffer sb = new StringBuffer("<div style=\"padding:24px 20px;font: bold 14px/22px arial,sans-serif;\">Dear " + 1 + " " + 2+ ","
                + "<br/>"
                + "<br/>We have received your WGS submission."
                + "<br/><table border=\"1\" ><tr> <th>Submission Title </th><th>Submission ID </th><th>BioProject</th><th>Biosample</th></tr>"
                + "<tr><td>"+2 + "</td><td>" + 3+ "</td><td>" + 4 + "</td><td>" +5+ "</td></tr></table>"
                + "<br/>After validation check processing, we have come across some issues which require your attention."
                + "<br/><br/>You need to check and be sure that all errors in the attached report files are fixed."
                + "<br/><br/>Please resubmit the corrected files at your convenience. To resubmit the corrected files, do not create a new submission. Instead, log back into genome submission portal, <a href='http://bigd.big.ac.cn/gwh/submit/submission'>http://bigd.big.ac.cn/gwh/submit/submission</a>. Revise the genome submission by clicking the corresponding submission ID, which is editable. Delete the files exist errors and upload replacement files, then click submit. Note that you need to reconfirm metadata from step1 to step6 when you revise your submission."
                +"<br/><br/>If you submit file by ftp, please log back into genome submission portal (<a href='http://bigd.big.ac.cn/gwh/submit/submission'>http://bigd.big.ac.cn/gwh/submit/submission</a>) after file submission, and click the \"Finish upload\" button in \"My Submissions\" list to inform us to check your submission."

                +"<br/><br/>Please send email to gwh@big.ac.cn if you have any question or revision about your submission!"
                +"<br/><br/>User:"+6
                + "<br/><br/>Sincerely,<br/>GWH team<br/><br/></div>");

        List<File> files =new ArrayList<>();
        files.add(new File("/home/gwh/nohup20170914.txt"));
        files.add(new File("/home/gwh/nohup20170908.txt"));

        // 发送邮件
        EmailUtils.sendHtmlMailWithAttach("Feedback validation about", sb.toString(), "wangfan@big.ac.cn",files);
        }catch (Exception e){
            return e.toString();

        }

        return "hello";

    }




    @RequestMapping(value = {"hello2"}, method = RequestMethod.GET)
    public Object hello2() {
        StringBuffer sb = new StringBuffer("<div style=\"padding:24px 20px;font: bold 14px/22px arial,sans-serif;\">Dear " + 1 + " " + 2+ ","
                + "<br/>"
                + "<br/>We have received your WGS submission."
                + "<br/><table border=\"1\" ><tr> <th>Submission Title </th><th>Submission ID </th><th>BioProject</th><th>Biosample</th></tr>"
                + "<tr><td>"+2 + "</td><td>" + 3+ "</td><td>" + 4 + "</td><td>" +5+ "</td></tr></table>"
                + "<br/>After validation check processing, we have come across some issues which require your attention."
                + "<br/><br/>You need to check and be sure that all errors in the attached report files are fixed."
                + "<br/><br/>Please resubmit the corrected files at your convenience. To resubmit the corrected files, do not create a new submission. Instead, log back into genome submission portal, <a href='http://bigd.big.ac.cn/gwh/submit/submission'>http://bigd.big.ac.cn/gwh/submit/submission</a>. Revise the genome submission by clicking the corresponding submission ID, which is editable. Delete the files exist errors and upload replacement files, then click submit. Note that you need to reconfirm metadata from step1 to step6 when you revise your submission."
                +"<br/><br/>If you submit file by ftp, please log back into genome submission portal (<a href='http://bigd.big.ac.cn/gwh/submit/submission'>http://bigd.big.ac.cn/gwh/submit/submission</a>) after file submission, and click the \"Finish upload\" button in \"My Submissions\" list to inform us to check your submission."

                +"<br/><br/>Please send email to gwh@big.ac.cn if you have any question or revision about your submission!"
                +"<br/><br/>User:"+6
                + "<br/><br/>Sincerely,<br/>GWH team<br/><br/></div>");
        EmailUtils.sendHtmlMail("test",sb.toString(), "wangfan@big.ac.cn");
        return "hello2";

    }


    @RequestMapping(value = {"hello3"}, method = RequestMethod.GET)
    public Object hello3() {

        return "hello3";

    }


    @RequestMapping(value = {"hello4"}, method = RequestMethod.GET)
    public Object hello4() {

        return "hello4";

    }

    @RequestMapping(value = {"hello5"}, method = RequestMethod.GET)
    public Object hello5() {

        return "hello5";

    }


    @RequestMapping(value = {"hello6"}, method = RequestMethod.GET)
    public Object hello6() {

        return "hello6";

    }






}
